package com.sloera.date;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author sloera
 * @create 2020/5/13
 */
public class TestSimpleDateFormat {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //date();
        localDate();
    }

    public static void localDate() throws ExecutionException, InterruptedException {
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");
        //DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL);
        Callable<LocalDate> callable = new Callable<LocalDate>() {
            @Override
            public LocalDate call() throws Exception {
                //return sdf.parse("20201221");
                return LocalDate.parse("20201221", dtf);
            }
        };
        ThreadPoolExecutor p = new ThreadPoolExecutor(5, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1024));
        List<Future> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(p.submit(callable));
        }
        for (Future<LocalDate> future : futures) {
            System.out.println(future.get());
        }
        p.shutdown();
    }

    public static void date() throws InterruptedException, ExecutionException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Callable<Date> callable = new Callable<Date>() {
            @Override
            public Date call() throws Exception {
                //return sdf.parse("20201221");
                return DateFormatThreadLocal.convert("20201221");
            }
        };
        ThreadPoolExecutor p = new ThreadPoolExecutor(5, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1024));
        List<Future> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(p.submit(callable));
        }
        for (Future<Date> future : futures) {
            System.out.println(future.get());
        }
        p.shutdown();
    }
}
